package com.bootdo.app.common.utils;

/**
  * @auther: Along
  * @description: 字符串校验工具类
  */
public class StringUtils {

    public static boolean isEmpty(String str) {
        String newStr = trimAllWhiteSpace(str);
        return newStr == null || "null".equalsIgnoreCase(newStr) || newStr.trim().length() == 0;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static boolean isEmpty(String... str) {
        if(str != null && str.length > 0){
            for (int i = 0; i < str.length; i++) {
                if (isEmpty(str[i])) {
                    return true;
                }
            }
            return false;
        }
        return true;
    }

    public static boolean isNotEmpty(String... str) {
        return !isEmpty(str);
    }

    public static String trimAllWhiteSpace(String str){
        if(str == null || "null".equalsIgnoreCase(str) || str.trim().length() == 0){
            return str;
        }
        int length = str.length();
        StringBuffer sb = new StringBuffer(length);
        for(int i = 0; i < length; i++){
            char c = str.charAt(i);
            if (!Character.isWhitespace(c)) {
                sb.append(c);
            }
        }
        return sb.toString();
    }


}
